package com.lzq.leetcode.hoot100;

import java.util.*;

public class s560 {

    public int subarraySum(int[] nums, int k) {
        int l = 0, r = 0;
        int sum = 0, ans = 0;

        for (; r<nums.length || sum >= k; ) {
            if (sum < k) {
                sum += nums[r++];
            } else if (sum > k) {
                sum -= nums[l++];
            } else {
                ans++;
                sum -= nums[l++];
            }
        }

        return ans;
    }
    public static void main(String[] args) {
        s560 s560 = new s560();
        PriorityQueue<int[]> pq = new PriorityQueue<>((e1, e2) -> e1[0] != e2[0] ? e2[0] - e1[0] : e1[1] - e2[1]);
        System.out.println(s560.subarraySum(new int[]{1, 2, 3}, 3));
    }
}
